<?php
	//echo $this->params->argv[0].'|'.count($this->params->argv);
	if(empty($this->params->argv) && (!isset($_SESSION['IS_LOGGED']) || FALSE==$_SESSION['IS_LOGGED']))
	{
		//如果用户没有登录则显示网页profile
		$html = '
		<body>
			<div class="anony-nav">
				<div class="hd-wrap">
					<div class="hd">
						<div class="logo">
							<a href="/tcbang"></a>
						</div>
						<div class="top-nav-items">
							<div id="search" class="mod">
								<form action="'.SITEURL.'search" method="post">
									<span class="inp" >
										<input class="basic-inp" type="text" size="25" value maxlength="120" title name="request" autocomplete="off" >
									</span>
									<span class="bn">
										<input type="submit" alt="搜成员 搜题目 搜小组" value="" class="bn-srh">
									</span>
									<span class="link_login">
										<a href="'.SITEURL.'login">登录</a>
									</span>
									<span class="link_userreg">
										<a href="'.SITEURL.'userreg">注册</a>
									</span>
								</form>
							</div>
						</div>
					</div>
				</div>
				<div class="bd">
				</div>
			</div>
			<div id="wrapper">
			</div>
		';
	}
	else
	{
		if(isset($_SESSION['IS_LOGGED']) && $_SESSION['IS_LOGGED'])
		{
			//如果用户登录则显示用户profile
			if(empty($this->params->argv) || strcmp($this->params->argv[0],$_SESSION['LOGGED_USER']->username) == 0)
			{
				//跳转到登录用户profile
				$html ='
				<p>这是你自己（'.$_SESSION['LOGGED_USER']->username.'）的profile.</p><br/>
				<a href="'.SITEURL.'home/">首页</a>
				';
			
			}
			else
			{
				//跳转其他用户的profile
				$_username = $this->db->escape($this->params->argv[0]);
				$uid = get_user_by_username($_username,TRUE,TRUE);
				if($uid == FALSE)
				{
					//目标用户不存在
					$html = '<p>用户' . $_username . '不存在</p>';
				}
				else
				{
					$o = $this->db->fetch('SELECT * FROM Follows WHERE who="' . $_SESSION['LOGGED_USER']->id . '" and whom="' . $uid . '" LIMIT 1');
					$html = '<p>这是'. $_username .'的profile.</p><br/>';
					
					$_SESSION['follow_uid'] = $uid;
					$_SESSION['follow_uname'] = $_username;
					
					if($o == FALSE)
					{
						//没有关注此好友，提供 '关注' 按钮
						$_SESSION['follow_type'] = 1;
						$html .= '
							<a href="'.SITEURL.'follow">
								<img src="' . SYSPIC_URL . 'follow_btn.jpg" alt="关注他">
							</a>
						';
					}
					else
					{
						//已经关注该好友，提供 '取消关注' 按钮
						$_SESSION['follow_type'] = 2;
						$html .= '
							<a href="'.SITEURL.'follow">
								<img src="' . SYSPIC_URL . 'dis_follow_btn.jpg" alt="关注他">
							</a>
						';	
					}
				}
			}
		}
		else
		{
			//用户没有登录则显示目标用户的profile
			$_username = $this->db->escape($this->params->argv[0]);
			$uid = get_user_by_username($_username,TRUE,TRUE);
			if($uid == FALSE)
			{
				$html = '<p>用户' . $_username . '不存在</p>';
			}
			else
			{
				$html = '<p>这是'. $_username .'的profile.</p><br/>';
			}
		}
	}
?>